Skip to content

Conversation

@andy31415
Copy link
Contributor

@andy31415 andy31415 commented Nov 6, 2025

Summary

Perform a global instance decoupling for the general commissioning cluster.

Picked this cluster since it has the most external dependencies, looked to see impact (flash and RAM) for a full decoupling of this.

Resource utilization

RAM: 24 bytes generally (6 references/pointers)
FLASH: O(150 bytes) for most platforms - was 100 before I added ::Destroy support in CodegenIntegration. Expect most overhead to be because codegen integration.

NM differ is somewhat confused because of preinit_array changes, however most changes seem to be to "destroy" existing now.

Type Size Function Size1 Size2
CHANGED -144 __preinit_array_start 61784 61928
REMOVED -68 (anonymous namespace)::ReadIfSupported(chip::ChipError (chip::DeviceLayer::ConfigurationManager::*)(unsigned char&), chip::app::AttributeValueEncoder&) [clone .constprop.0] 0 68
CHANGED -52 _GLOBAL__sub_I__ZN4chip3app8Clusters20GeneralCommissioning8InstanceEv 24 76
CHANGED -48 (anonymous namespace)::gRegistration 8 56
CHANGED -20 chip::app::Clusters::GeneralCommissioningCluster::HandleCommissioningComplete 332 352
CHANGED -8 MatterGeneralCommissioningClusterInitCallback 40 48
CHANGED -8 chip::app::Clusters::GeneralCommissioningCluster::HandleArmFailSafe 204 212
CHANGED -8 chip::app::Clusters::GeneralCommissioningCluster::Shutdown 40 48
CHANGED -4 chip::app::Clusters::GeneralCommissioningCluster::HandleSetRegulatoryConfig 288 292
CHANGED -4 chip::app::Clusters::GeneralCommissioningCluster::Startup 44 48
REMOVED -2 chip::app::RegisteredServerClusterchip::app::Clusters::GeneralCommissioningCluster::~RegisteredServerCluster 0 2
CHANGED 4 chip::app::Clusters::GeneralCommissioningCluster::ReadAttribute 240 236
CHANGED 12 chip::app::Clusters::GeneralCommissioning::Instance 20 8
ADDED 16 chip::app::LazyRegisteredServerClusterchip::app::Clusters::GeneralCommissioningCluster::~LazyRegisteredServerCluster 16 0
CHANGED 24 (anonymous namespace)::gServer 80 56
ADDED 42 chip::app::LazyRegisteredServerClusterchip::app::Clusters::GeneralCommissioningCluster::Destroy 42 0
ADDED 62 (anonymous namespace)::ReadIfSupported(chip::DeviceLayer::ConfigurationManager&, chip::ChipError (chip::DeviceLayer::ConfigurationManager::*)(unsigned char&), chip::app::AttributeValueEncoder&) [clone .constprop.0] 62 0

Testing

No functional changes and general commissioning is heavily exercised in CI. Existing CI tests are expected to check that no functional changes were made.

Copilot AI review requested due to automatic review settings November 6, 2025 20:39
@pullapprove pullapprove bot added review - pending and removed app labels Nov 6, 2025
@mergify
Copy link

mergify bot commented Nov 6, 2025

⚠️ The sha of the head commit of this PR conflicts with #41689. Mergify cannot evaluate rules on this PR. ⚠️

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively refactors the General Commissioning cluster to use dependency injection, removing its reliance on global singletons. This is a significant improvement for modularity and testability. The implementation is clean and consistently applies the new pattern across the cluster's logic. I have two minor suggestions for cleanup in the test files to further improve the codebase.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the GeneralCommissioningCluster to use dependency injection instead of accessing global singletons directly. The cluster now receives its dependencies through a Context struct passed to the constructor, improving testability and explicit dependency management.

Key Changes

  • Introduced a Context struct containing all external dependencies (CommissioningWindowManager, ConfigurationManager, DeviceControlServer, FabricTable, FailSafeContext, PlatformManager, and optionally TermsAndConditionsProvider)
  • Changed cluster instantiation from eager to lazy using LazyRegisteredServerCluster
  • Updated all singleton accesses within the cluster to use injected dependencies from mClusterContext

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
general-commissioning-cluster.h Added Context struct with dependency references; updated constructor to accept Context and OptionalAttributes
general-commissioning-cluster.cpp Modified all methods to use injected dependencies from mClusterContext instead of global singletons
CodegenIntegration.cpp Changed from RegisteredServerCluster to LazyRegisteredServerCluster; Context is constructed during CreateRegistration
TestGeneralCommissioningCluster.cpp Updated tests to construct cluster with proper Context initialization
TestNetworkCommissioningCluster.cpp Added includes and minor formatting cleanup
thread-border-router-management-server.cpp Added include for general-commissioning-cluster.h header
app_config_dependent_sources.cmake Added CodegenIntegration.h to target sources

@github-actions github-actions bot added the app label Nov 6, 2025
Copilot AI review requested due to automatic review settings November 6, 2025 20:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

@andy31415
Copy link
Contributor Author

/gemini review

Copilot AI review requested due to automatic review settings November 6, 2025 20:55
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the General Commissioning cluster to use dependency injection, decoupling it from global singletons. This is a significant improvement for testability and maintainability. The changes are well-implemented across the cluster's source, header, and test files. The core change is the introduction of a Context struct to hold dependencies, which is passed during the cluster's construction. The implementation correctly uses a LazyRegisteredServerCluster to manage the lifecycle of the cluster instance. My review found one area for improvement in the test code to reduce duplication.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings November 6, 2025 21:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

PR #41833: Size comparison from 4940afb to 4d885df

Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 4940afb 4d885df change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106340 1106572 232 0.0
RAM 178930 178954 24 0.0
bl702 lighting-app bl702+eth FLASH 661414 661390 -24 -0.0
RAM 135025 135041 16 0.0
bl702+wifi FLASH 837008 836984 -24 -0.0
RAM 124445 124477 32 0.0
bl706+mfd+rpc+littlefs FLASH 1070610 1070842 232 0.0
RAM 117317 117349 32 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 900042 900274 232 0.0
RAM 105612 105628 16 0.0
lighting-app bl702l+mfd+littlefs FLASH 983356 983588 232 0.0
RAM 109796 109828 32 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 770820 770972 152 0.0
RAM 103360 103384 24 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 782664 782792 128 0.0
RAM 108528 108552 24 0.0
pump-app LP_EM_CC1354P10_6 FLASH 728612 728740 128 0.0
RAM 97420 97444 24 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 713080 713216 136 0.0
RAM 97636 97660 24 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 554906 555034 128 0.0
RAM 205776 205800 24 0.0
lock CC3235SF_LAUNCHXL FLASH 587786 587922 136 0.0
RAM 205872 205896 24 0.0
efr32 lock-app BRD4187C FLASH 963504 963640 136 0.0
RAM 123572 123604 32 0.0
BRD4338a FLASH 757752 757896 144 0.0
RAM 254196 254220 24 0.0
window-app BRD4187C FLASH 1058820 1058956 136 0.0
RAM 119800 119832 32 0.0
esp32 all-clusters-app c3devkit DRAM 102572 102596 24 0.0
FLASH 1836720 1836870 150 0.0
IRAM 93540 93540 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 933452 933592 140 0.0
RAM 161377 161401 24 0.0
nxp contact mcxw71+release FLASH 692504 692648 144 0.0
RAM 61552 61576 24 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1678092 1678244 152 0.0
RAM 213956 213980 24 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1594492 1594628 136 0.0
RAM 211156 211180 24 0.0
light cy8ckit_062s2_43012 FLASH 1460732 1460868 136 0.0
RAM 197776 197800 24 0.0
lock cy8ckit_062s2_43012 FLASH 1493420 1493556 136 0.0
RAM 225496 225520 24 0.0
qpg lighting-app qpg6200+debug FLASH 837768 837896 128 0.0
RAM 127768 127792 24 0.0
lock-app qpg6200+debug FLASH 774580 774724 144 0.0
RAM 118736 118760 24 0.0
realtek light-switch-app rtl8777g FLASH 706952 707080 128 0.0
RAM 106964 106988 24 0.0
lighting-app rtl8777g FLASH 757896 758032 136 0.0
RAM 127296 127320 24 0.0
stm32 light STM32WB5MM-DK FLASH 470224 470368 144 0.0
RAM 141352 141376 24 0.0
telink bridge-app tl7218x FLASH 710608 710704 96 0.0
RAM 90600 90624 24 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 797084 797180 96 0.0
RAM 41024 41048 24 0.1
light-app-ota-shell-factory-data tl7218x FLASH 788286 788382 96 0.0
RAM 93700 93724 24 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 715286 715382 96 0.0
RAM 51892 51916 24 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 748582 748678 96 0.0
RAM 70932 70956 24 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 725436 725532 96 0.0
RAM 34624 34648 24 0.1
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 602672 602768 96 0.0
RAM 108928 108952 24 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 820918 821018 100 0.0
RAM 92096 92120 24 0.0

${APP_TARGET}
PRIVATE
"${CLUSTER_DIR}/CodegenIntegration.cpp"
"${CLUSTER_DIR}/CodegenIntegration.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No such file in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was probably missed before and things just compile because headers will work. File does exist, but I did not change it:

https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/general-commissioning-server/CodegenIntegration.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants